﻿using System;
using System.Collections.Generic;
using System.Text;
using FunctionalCLR;
using FunctionalCLR.Core;

namespace FunctionalCLR.Shell.Function {
    public class IfNode : FuncNode {

        public IfNode()
            : base() {
            base.Value = "if";
        }

        public override FuncNode GetReversedFunction(int index) {
            throw new NotImplementedException();
        }

        public override object Evaluate() {
            string result = Children[0].Evaluate().ToString();

            if (result.ToLower() == "true") {
                result = Children[1].Evaluate().ToString();
            } else {
                if (Children.Count > 2) {
                    result = Children[2].Evaluate().ToString();
                } else {
                    result = string.Empty;
                }
            }

            return result;
        }

        public override object Accept(IVisitor visitor) {
            throw new NotImplementedException();
        }
    }
}
